

#ifndef EM_COMMON_I2C_H__
#define EM_COMMON_I2C_H__

#include <stdint.h>
#include <stdbool.h>

#include "app_i2c.h"

#define COMMON_I2C_SUCCESS      APP_DRV_SUCCESS

void em_common_i2c_init(void); 

//static inline uint16_t em_common_i2c_read_byte(uint8_t slave, uint8_t addr, uint8_t *data ) 
//{
//    return  app_i2c_mem_read_sync( 
//                            COMMON_I2C_ID,
//                            slave, 
//                            addr, 
//                            1,
//                            data,
//                            1,
//                            10
//                         );
//    
////    return ret ; 
//}
//static inline uint16_t em_common_i2c_write_byte( uint8_t slave, uint8_t addr, uint8_t data)
//{
//    return app_i2c_mem_write_sync(
//                            COMMON_I2C_ID,  // i2c Instance 
//                            slave,          // slave address
//                            addr,           // reg address
//                            1,              // address length, default 1
//                            &data,          // data to write 
//                            1,              // 1byte
//                            10              // timeout 
//                          ) ;
//    
////    return ret == APP_DRV_SUCCESS; 
//}

static inline uint16_t em_common_i2c_read_bytes( uint8_t slave, uint8_t addr, uint8_t* p_buffer, uint16_t len)
{
    return app_i2c_mem_read_sync( 
                                    COMMON_I2C_ID, 
                                    slave, 
                                    addr, 
                                    1, 
                                    p_buffer, 
                                    len, 
                                    10 
                                );
}


static inline uint16_t em_common_i2c_write_bytes( uint8_t slave,
                                                uint8_t addr, 
                                                uint8_t* p_buff,
                                                uint16_t length )
{
    return app_i2c_mem_write_sync( 
                                    COMMON_I2C_ID,
                                    slave,
                                    addr,
                                    1, 
                                    p_buff,
                                    length,
                                    10 
                                );
}
static inline uint16_t em_common_i2c_mem_read( uint8_t slave,
    uint16_t addr,
    uint8_t* p_buff,
    uint16_t length ) 
{
    return app_i2c_mem_read_sync(
                                    COMMON_I2C_ID,
                                    slave,
                                    addr,
                                    2,
                                    p_buff,
                                    length,
                                    10
                                 );
}


#endif 
